<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<style>
</style>
<body>
    <div id="app">
       <p>
           <input type="text" v-model="username">
           <span v-if="isShow">长度已经大于六位了！</span>
       </p>
       <p>
           <input type="text" v-model="person.name">
       </p>
    </div>

    <script src="./base/vue.js"></script>
    <script>
        new Vue({
            el:"#app",
            data: {
                username:"",
                isShow:false,
                person:{
                    name:"张三"
                }
            }, 
            watch:{
                // "person.name":{
                //     immediate:true,
                //     handler(newValue){
                //         console.log("person.name发生改变了。。")
                //     }
                // },
                person:{
                    immediate:true,
                    deep:true,//代表深度监听  对象的里面的属性发生改变了，监听对象，也可以触发handler函数。
                    handler(newValue){
                        console.log("person.name发生改变了。。")
                    }
                },
                username:{
                    immediate:true,
                    handler(newValue){
                        if(newValue.length > 6 && !this.isShow){
                            this.isShow = true;
                        }else if(newValue.length <= 6 && this.isShow){
                            this.isShow = false
                        }
                    }
                }
            }
        })


    </script>
</body>
</html>